package com.xbts.system.domain;
import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.Data;
import com.xbts.common.annotation.Excel;
import com.xbts.common.utils.StringUtils;
import com.xbts.common.core.domain.BaseEntity;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Date;
import java.util.Objects;

/**
 * 标书对象 sei_task
 *
 * @author xbts
 * @date 2023-08-18
 */
@Data
@ApiModel("标书对象")
@TableName("sei_task")
public class SeiTask extends BaseEntity {

    private static final long serialVersionUID=1L;

    /** 标书Id */
    @TableId
    private String tenderId;

    @ApiModelProperty("类型ID")
    private String typeId;

    @TableField(exist = false)
    @ApiModelProperty("类型名称")
    private String typeName;

    /** 下达状态 */
    @Excel(name = "下达状态",readConverterExp = "(0已下达 1未下达。")
    @ApiModelProperty("下达状态")
    private Boolean giveStatus;

    @ApiModelProperty("下达意见")
    private String giveRemark;

    /** 执行状态 */
    @Excel(name = "执行状态",readConverterExp = "(1已完成 0正在执行)")
    @ApiModelProperty("执行状态")
    private Boolean executionStatus;

    /** 投标负责人 */
    @Excel(name = "投标负责人")
    @ApiModelProperty("投标负责人")
    private String headOfTender;

    @ApiModelProperty("投标负责人名称")
    @TableField(exist = false)
    private String headOfTenderName;

    /** 项目名称 */
    @Excel(name = "项目名称")
    @ApiModelProperty("项目名称")
    private String projectName;

    /** 投标截止时间 */
    @Excel(name = "投标截止时间")
    @ApiModelProperty("投标截止时间")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private String bidDeadline;

    /** 招标方 */
    @Excel(name = "招标方")
    @ApiModelProperty("招标方")
    private String tenderer;

    @ApiModelProperty("招标方名称")
    @TableField(exist = false)
    private String tendererName;

    /** 代理机构 */
    @Excel(name = "代理机构")
    @ApiModelProperty("代理机构")
    private String agency;

    /** 招标平台 */
    @Excel(name = "招标平台")
    @ApiModelProperty("招标平台")
    private String tenderPlatform;

    @ApiModelProperty("招标平台名称")
    @TableField(exist = false)
    private String tenderPlatformName;

    /** 所属专业 */
    @Excel(name = "所属专业")
    @ApiModelProperty("所属专业")
    private String major;

    @ApiModelProperty("所属专业名称")
    @TableField(exist = false)
    private String majorName;

    /** 技术负责人 */
    @Excel(name = "技术负责人")
    @ApiModelProperty("技术负责人")
    private String headOfTech;

    @ApiModelProperty("技术负责人名称")
    @TableField(exist = false)
    private String headOfTechName;

    /** 开标时间 */
    @Excel(name = "开标时间")
    @ApiModelProperty("开标时间")
    private String tenderDate;

    /** 网址 */
    @Excel(name = "网址")
    @ApiModelProperty("网址")
    private String url;

    /** 预计竞标单位 */
    @Excel(name = "预计竞标单位")
    @ApiModelProperty("预计竞标单位")
    private String expectedCompetitor;

    /** 中标金额 */
    @Excel(name = "中标金额")
    @ApiModelProperty("中标金额")
    private String amount;

    /** 是否总承包 */
    @Excel(name = "是否总承包",readConverterExp = "value=1;是， value=0;否")
    @ApiModelProperty("是否总承包")
    private Boolean whetherGeneralContract;

    /** 是否中标 */
    @Excel(name = "是否中标",readConverterExp = "value=1;是， value=0;否")
    @ApiModelProperty("是否中标")
    private Boolean whetherWinBid;

    /** 是否完成 */
    @Excel(name = "是否完成",readConverterExp = "value=1;是， value=0;否")
    @ApiModelProperty("是否完成")
    private Boolean whetherComplete;

    /** 是否退还金额 */
    @Excel(name = "是否退还金额",readConverterExp = "value=1;是， value=0;否")
    @ApiModelProperty("是否退还金额")
    private Boolean whetherRefund;

    /** 退款金额 */
    @Excel(name = "退款金额")
    @ApiModelProperty("退款金额")
    private Double refundAmount;

    /** 退款联系方式  */
    @Excel(name = "退款联系方式")
    @ApiModelProperty("退款联系方式")
    private String refundContact;

    /** 上传通知  */
    @Excel(name = "上传通知")
    @ApiModelProperty("上传通知")
    private String uploadNotification;


    @ApiModelProperty("标书详情")
    private String tenderDetails;

    @ApiModelProperty("总时长")
    private Long totalDuration;

    /** 完成时间 */
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date completeTime;

    @ApiModelProperty("是否已读: (1未读，2已读)")
    private Integer readStatus;



    public<T> QueryWrapper<T> queryWrapper(){
        QueryWrapper<T> queryWrapper=new QueryWrapper<>();
        queryWrapper.like(StringUtils.isNotEmpty(projectName),"t.project_name",projectName);
        queryWrapper.like(!Objects.isNull(tenderer),"t.tenderer",tenderer);
        queryWrapper.like(!Objects.isNull(agency),"t.agency",agency);
        queryWrapper.like(!Objects.isNull(tenderPlatform),"t.tender_platform",tenderPlatform);
        queryWrapper.like(!Objects.isNull(major),"t.major",major);
        queryWrapper.like(!Objects.isNull(headOfTech),"t.head_of_tech",headOfTech);
        queryWrapper.like(StringUtils.isNotEmpty(tenderDate),"t.tender_date",tenderDate);
        queryWrapper.like(StringUtils.isNotEmpty(url),"t.url",url);
        queryWrapper.like(StringUtils.isNotEmpty(expectedCompetitor),"t.expected_competitor",expectedCompetitor);
        queryWrapper.eq(!Objects.isNull(amount),"t.amount",amount);
        queryWrapper.eq(!Objects.isNull(refundAmount),"t.refund_amount",refundAmount);
        queryWrapper.like(StringUtils.isNotEmpty(refundContact),"t.refund_contract",refundContact);
        queryWrapper.like(StringUtils.isNotEmpty(uploadNotification),"t.upload_notification",uploadNotification);
        queryWrapper.like(StringUtils.isNotEmpty(bidDeadline),"t.bid_deadline",bidDeadline);
        queryWrapper.like(StringUtils.isNotEmpty(headOfTender),"t.head_of_tender",headOfTender);
        queryWrapper.like(StringUtils.isNotEmpty(projectName),"t.project_name",projectName);
        queryWrapper.eq(!Objects.isNull(whetherComplete),"t.whether_complete",whetherComplete);
        queryWrapper.eq(!Objects.isNull(readStatus),"t.read_status",readStatus);
        queryWrapper.orderByDesc("t.create_time");
        return queryWrapper;
    }
}